package com.shop.cereshop.admin.service.history.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.cereshop.admin.dao.history.CereWebHistoryDAO;
import com.shop.cereshop.admin.param.history.WebHistoryParam;
import com.shop.cereshop.admin.service.history.CereWebHistoryService;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.history.CereWebHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CereWebHistoryServiceImpl implements CereWebHistoryService {
    @Autowired
    CereWebHistoryDAO cereWebHistoryDAO;
    public Integer addHistory(Long webPlatformUserId, String webName,
                              String webPhone,String webAvatar,
                              String webAction,String webResult
                             ,Integer webActionType){
        CereWebHistory cereWebHistory = new CereWebHistory();
        cereWebHistory.setWebPlatformUserId(webPlatformUserId);
        cereWebHistory.setWebName(webName);
        cereWebHistory.setWebPhone(webPhone);
        cereWebHistory.setWebAvatar(webAvatar);
        cereWebHistory.setWebAction(webAction);
        cereWebHistory.setWebActionTime(LocalDateTime.now());
        cereWebHistory.setWebActionResult(webResult);

        return cereWebHistoryDAO.insert(cereWebHistory);
    }
    public Page<CereWebHistory> getHistory(WebHistoryParam webHistoryParam){
        PageHelper.startPage(webHistoryParam.getPage(),webHistoryParam.getPageSize());
         List<CereWebHistory>  list =cereWebHistoryDAO.selectLists(webHistoryParam);
        PageInfo<CereWebHistory> cereWebHistoryPageInfo = new PageInfo<>(list);
        return new Page<>(cereWebHistoryPageInfo.getList(),cereWebHistoryPageInfo.getTotal());

    }
}
